package com.otaku.common.util;

import com.alibaba.fastjson.JSONObject;
import com.otaku.common.ResultUtils.ResultModel;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

/**
 * 第三方请求工具类
 */
public class RestTemplateUtils {

    /**
     * 发送消息
     * @param url
     * @return
     */
    public static ResultModel sendMsg(String url) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
        HttpEntity<String> entity = new HttpEntity<>(headers);
        String body = restTemplate.exchange(url, HttpMethod.GET, entity, String.class).getBody();
        GoJsonEntity goJsonEntity = JSONObject.parseObject(body,GoJsonEntity.class);
        GoJsonEntity.DataBean data = goJsonEntity.getData();
        ResultModel resultModel = new ResultModel(data.getCode(),null,data.getMessage(),null,null);
        return resultModel;
    }
}
